
#include "TUIBase.h"
#include "test/globaldef.h"

static int timeCount = 0;
int TUITask()
{ 

  int count=0,i=0;
  char packBuff[RD_BUF_SIZE];

  for(i=0;i<TUI_CH_NUM;i++) // load the last method to status
  {
    m_TUIStatus.CHs[i] = m_TUIConfig.MethodUsing.CHs[i];
    m_TUIStatus.CHs[i].setON = 0; //at the beginning not open the channel
    TUI_setCH_config(i);
  }

  TUI_changeGeneral(0x06,0);
  TUI_dispRUNState();
  TUI_dispHome();
  TUI_dispPage(PAGE_HOME);

  while(allRun_flag)
  {
//parse cmd from TUI
    count = TUI_readCmd(packBuff,RD_BUF_SIZE);
    if(count > 0)
      TUI_parseRecv(packBuff,count);

    timeCount++;
    if(timeCount > 2000)
      timeCount = 1;

    if(packet_read(DRTC_PORT,packBuff,RD_BUF_SIZE) > 0)
    {
      TUI_packetParse(packBuff, strlen(packBuff));
      TUI_dispAllStatus();
      //TUI_updateMethodStatus();
    }
    if(timeCount % 300 == 0)
    {
      TUI_readStatus();
    }
    if(timeCount % 2000 == 0)
      TUI_updateInfo();

    Task_yield();
  }
  return 0;
}
